Skip to content

fix(server): avoid reusing an acquired reserved port - #5608

Merged
fatedier merged 1 commit into
fatedier:devfrom
shoutoutuoadi325:fix/reserved-port-allocation
Nov 10, 2026
Merged

fatedier merged 1 commit into
fatedier:devfrom
shoutoutuoadi325:fix/reserved-port-allocation

Conversation

@shoutoutuoadi325

Copy link
Copy Markdown
Contributor

WHY

Fixes #5607.

A proxy reconnecting with remotePort = 0 could reclaim its previous port after another proxy acquired it but before that proxy bound its socket. The successful socket probe let the reconnect overwrite the active allocation.

Check the manager's free-port set before probing the remembered port. If it has already been acquired, use the existing random allocation path. This preserves reuse when the previous port is free and leaves the other proxy's allocation intact.

Tests

  • Added a TCP and UDP regression covering reuse, contention before bind, and fallback to a different port. Both subtests fail on current dev and pass with this change.
  • go test -race ./server/ports -count=25
  • go test -tags noweb ./assets/... ./cmd/... ./client/... ./server/... ./pkg/...
  • make build and both existing Alloc Random Port end-to-end specs (legacy and v1)

Copilot AI balanced review requested due to automatic review settings November 6, 2026 14:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@kilo-code-bot

kilo-code-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • server/ports/ports.go
  • server/ports/ports_test.go

Reviewed by gpt-6.1-sol · Input: 36 · Output: 2.3K · Cached: 322.8K

@fatedier
fatedier merged commit a2c975e into fatedier:dev Nov 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

frps can reallocate a reserved port before another proxy binds it

3 participants